import Vue from 'vue'
import Vuex from 'vuex'
import { vue, react, wechat, across, compileBuild } from '@/constants/docs'
import { frontEndTools, OfficeTools } from '@/constants/tools'
import { tools, docs, community } from '@/constants/asideData'
import { blogs } from '@/constants/community'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        content: 'home',
        asideData: [],
        mainData: [],
    },
    mutations: {
        setContent(state, content) {
            state.content = content
        },
        setAsideData(state, key) {
            const asideActions = {
                '2': tools,
                '3': docs,
                '4': community,
            }
            state.asideData = asideActions[key]
        },
        setMainData(state, menuItemText) {
            const actions = new Map([
                // 工具
                ['前端工具', frontEndTools],
                ['办公工具', OfficeTools],
                // 文档
                ['vue', vue],
                ['react', react],
                ['微信开发', wechat],
                ['跨端框架', across],
                ['编译构建', compileBuild],
                // 社区
                ['博客', blogs],
            ])

            state.mainData = actions.get(menuItemText)
        },
    },
    actions: {},
    modules: {},
})
